<template>
  <common-list>
    <!-- 头部搜素start -->
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        @submit.native.prevent
        :model="query"
        ref="queryForm"
        :inline="true"
        label-width="90px"
      >
        <el-form-item label="活跃状态" prop="isActive">
          <el-select v-model="query.isActive">
            <el-option label="全部" :value="null"></el-option>
            <el-option label="正常" :value="0"></el-option>
            <el-option label="未知" :value="1"></el-option>
            <el-option label="僵尸" :value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="业务系统" prop="businessName">
          <el-select v-model="query.businessName" class="custom-select">
            <el-option label="全部" :value="null"></el-option>
            <el-option
              class="custom-select"
              v-for="item in businessCodeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictLabel"
            >
              <span class="selectList">
                <common-marquee-text :content="item.dictLabel">
                </common-marquee-text>
              </span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="IP" prop="domain">
          <common-input
            v-model="query.domain"
            :verify="false"
            clearable
            @enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="是否敏感接口" prop="isSensitiveId">
          <el-select v-model="query.isSensitiveId">
            <el-option label="全部" :value="null"></el-option>
            <el-option label="正常" :value="0"></el-option>
            <el-option label="敏感" :value="1"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </common-search>
    <!-- 头部搜素end -->

    <!--列表 start-->
    <common-table slot="content" v-loading="loading" :data="list">
      <el-table-column
        label="业务系统"
        prop="businessName"
        align="left"
        width="160"
      />

      <el-table-column
        label="IP"
        align="left"
        prop="domain"
        width="160"
      ></el-table-column>

      <el-table-column
        label="接口"
        align="left"
        prop="url"
        show-overflow-tooltip
      ></el-table-column>

      <el-table-column
        label="活跃状态"
        align="left"
        show-overflow-tooltip
        width="140"
      >
        <template slot-scope="{ row }">
          {{
            row.isActive === 0
              ? "正常"
              : row.isActive === 1
              ? "未知"
              : row.isActive === 2
              ? "僵尸"
              : null
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="是否敏感接口"
        align="left"
        prop="isSensitive"
        width="120"
        show-overflow-tooltip
      >
        <template slot-scope="{ row }">
          {{
            row.isSensitive === 0
              ? "正常"
              : row.isSensitive === 1
              ? "敏感"
              : null
          }}
        </template></el-table-column
      >
      <el-table-column
        label="方法"
        align="left"
        prop="method"
        width="120"
        show-overflow-tooltip
      ></el-table-column>
    </common-table>
    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />
  </common-list>
</template>

<script>
import BaseList from "@/mixins/BaseList";
import { list } from "@/api/apisecurity/viewBoard/index";
import { getBusinessSystemName } from "@/api/system/application/application";

export default {
  mixins: [BaseList],
  props: {},
  data() {
    return {
      filterMenu: "", //菜单筛选
      showSearch: true, // 查询部分显示
      total: 0, // 总条数
      loading: false, // table 加载中
      list: [], // 数据列
      query: {
        pageNum: 1,
        pageSize: 10,
        businessName: null,
        isActive: null,
        isSensitiveId: null,
      }, // 查询条件
      exportLoading: false,
      businessCodeList: [],
    };
  },
  watch: {},
  computed: {},
  methods: {
    //导出
    handleExport() {
      this.exportLoading = true;
      this.download(
        "/system/assetAudit/export",
        {
          ...this.queryParams,
          pageSize: 10000,
        },
        `资产审计${new Date().getTime()}.txt`,
        20000
      ).finally(() => {
        this.exportLoading = false;
      });
    },
    queryBusinessCodeList() {
      getBusinessSystemName().then((res) => {
        if (res && res.code === 200) {
          this.businessCodeList = res.data;
        } else {
          this.businessCodeList = [];
        }
      });
    },
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      list(this.query)
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            this.list = [];
            this.total = 0;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /**
     * 查询
     */
    handleQuery() {
      this.query.pageNum = 1;
      this.getList();
    },
    /**
     * 重置查询
     */
    resetQuery() {
      this.query = this.$options.data().query;
    },
  },
  created() {
    this.getList();
    this.queryBusinessCodeList();
  },
  mounted() {},
};
</script>
